import * as actionTypes from "./constants";
import {
    gitRankingMenuList,
    gitRankingContent,
    gitMusicUrl,
    gitMusicDetail,
} from "@/services/ranking";

const changeMenutAction = (res) => ({
    type: actionTypes.CHANGE_RANKING,
    rankingMenuList: res.list,
});
const changeContentAction = (res) => ({
    type: actionTypes.CHANGE_CONTENT,
    rankingConten: res.playlist,
});
const changeMusicUrlAction = (res) => ({
    type: actionTypes.CHANGE_MUSIC_URL,
    musicUrl: res,
});
const changeMusicDetailsAction = (res) => ({
    type: actionTypes.CHANGE_MUSIC_DETAILS,
    musicDetails: res,
});
//排行榜歌单
export const getRankingMenuAction = () => {
    return (dispatch) => {
        gitRankingMenuList().then((res) => {
            dispatch(changeMenutAction(res));
        });
    };
};
//排行榜歌单详情
export const getRankingConentAction = (id) => {
    return (dispatch) => {
        gitRankingContent(id).then((res) => {
            res.playlist.trackUpdateTime = new Date(res.playlist.trackUpdateTime).Format(
                "yy-MM-dd"
            );
            dispatch(changeContentAction(res));
        });
    };
};
//音乐url
export const geMusicUrlAction = (id) => {
    return (dispatch) => {
        gitMusicUrl(id).then((res) => {
            dispatch(changeMusicUrlAction(res.data));
        });
    };
};
//音乐详情
export const gitMusicDetailAction = (id) => {
    return (dispatch) => {
        gitMusicDetail(id).then((res) => {
            dispatch(changeMusicDetailsAction(res.songs));
        });
    };
};
